package com.my.blogapi.controller;

import com.my.blogapi.commo.aop.Cache;
import com.my.blogapi.commo.aop.LogAspect;
import com.my.blogapi.service.ArticleService;
import com.my.blogapi.vo.param.ArticleParam;
import com.my.blogapi.vo.param.PageParams;
import com.my.blogapi.vo.param.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @LogAspect(module="文章列表",operation="获取首页博客文章")
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams){
        return articleService.listArticle(pageParams);
    }

    /**
     * 最热文章
     */
    @Cache(name = "hot_article")
    @PostMapping("hot")
    public Result hotArticle(){
        int limit = 5;
        return articleService.hotArticle(limit);
    }
    /**
     * 最新文章
     */
    @PostMapping("new")
    public Result newArticle(){
        int limit = 5;
        return articleService.newArticle(limit);
    }

    /**
     * 文章归档
     */
    @PostMapping("listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }
    @PostMapping("publish")
    public Result articlePublish(@RequestBody ArticleParam articleParam){
        return articleService.publishArticle(articleParam);
    }

}
